package creation.simplefactory;

/**
 * @author wangjinqiang
 * @date 2019-08-09
 */
public class VideoFactory {
    public Video getVideo(String type) {
        if ("java".equalsIgnoreCase(type)) {
            return new JavaVideo();
        } else if ("python".equalsIgnoreCase(type)) {
            return new PythonVideo();
        }
        return null;
    }

    /**
     * 用反射创建对象，避免判断
     */
    public Video getVideoByClass(Class<? extends Video> c) {
        try {
            return c.newInstance();
        } catch (InstantiationException | IllegalAccessException e) {
            e.printStackTrace();
        }
        return null;
    }
}
